// import { createApp } from 'vue'
// import App from './App.vue'
// import Router from './router'
import Vue from 'vue'
import Router from 'vue-router'
import Loginnav from './components/Loginnav.vue'
import Login from './views/Login.vue'
import Desc from './views/Desc.vue'
import Time from './views/Time.vue'


//管理员
import Admin from "@/views/Admin/Admin.vue"
import StudentInfo from "@/views/Admin/StudentInfo.vue"
import InsertStudentInfo from "@/views/Admin/InsertStudentInfo.vue"
import TeacherInfo from "@/views/Admin/TeacherInfo.vue"
import InsertTeacherInfo from "@/views/Admin/InsertTeacherInfo.vue"
import CourseInfo from "@/views/Admin/CourseInfo.vue"
import InsertCourseInfo from "@/views/Admin/InsertCourseInfo.vue"
import Grade from "@/views/Admin/Grade.vue"
import InsertGrade from "@/views/Admin/InsertGrade.vue"
import Chart from "@/views/Admin/Chart.vue"

//老师
import teacher from "@/views/Teacher/index";
import offerCourseList from "@/views/Teacher/offerCourseList";
import teacherHome from "@/views/Teacher/home";
import setCourse from "@/views/Teacher/setCourse";
import myOfferCourse from "@/views/Teacher/myOfferCourse";
import teacherGradeCourseManage from "@/views/Teacher/teacherGradeCourseManage/index";

import teacherGradeCourseList from "@/views/Teacher/teacherGradeCourseManage/teacherGradeCourseList";
import teacherEditorGradeCourse from "@/views/Teacher/teacherGradeCourseManage/teacherEditorGradeCourse";

//学生
import student from "@/views/Student/index";
import studentHome from "@/views/Student/home";
import studentSelectCourseManage from "@/views/Student/selectCourse/index";
import selectCourse from "@/views/Student/selectCourse/selectCourseList";
import querySelectedCourse from "@/views/Student/selectCourse/querySelectedCourse";
import courseTable from "@/views/Student/selectCourse/courseTable";
import studentCourseGrade from "@/views/Student/courseGrade/index";
import queryCourseGrade from "@/views/Student/courseGrade/queryCourseGrade";
// createApp(App).use(router).mount('#app')
import updateInfo from "@/components/updateInfo";

Vue.use(Router)

const router = new Router({
    routes: [
  { path: '/', redirect: '/loginnav' },
  {//登录页面
         path: '/loginnav', component: Loginnav,
        redirect:'/desc',
        children:[
        { path: '/login', component: Login },
        { path: '/desc', component: Desc },
        { path: '/time', component: Time },]
  },
  {//管理员
      path:'/admin',
      component:Admin,
      redirect:'/studentInfo',
      children:[
          {
              path:'/studentInfo',
              component:StudentInfo,
          },
          {
              path:'/insertStudentInfo',
              component:InsertStudentInfo,
              meta: {requireAuth: true},
          },
          {
            path:'/teacherInfo',
            component:TeacherInfo,
            meta: {requireAuth: true},
        },
        {
            path:'/insertTeacherInfo',
            component:InsertTeacherInfo,
            meta: {requireAuth: true},
        },
          {
              path:'/courseInfo',
              component:CourseInfo,
              meta: {requireAuth: true},
          },
          {
              path:'/insertCourseInfo',
              component:InsertCourseInfo,
              meta: {requireAuth: true},
          },
          {
              path:'/grade',
              component:Grade,
              meta: {requireAuth: true},
          },
          {
              path:'/insertGrade',
              component:InsertGrade,
              meta: {requireAuth: true},
          },
          {
              path:'/chart',
              component:Chart,
              meta: {requireAuth: true},
          }
      ]
  },  
  {//教师页面
    path: '/teacher',
    name: 'teacher',
    component: teacher,
    redirect: '/teacherHome',
    children: [
      {
        path: '/teacherHome',
        name: 'Hi! teacher',
        component: teacherHome,
        children: [
          {
            path: '/teacherHome',
            name: '教师主页',
            meta: {requireAuth: true},
            component: teacherHome
          },
        ]
      },
      {
        path: '/updateInfo',
        name: '教师编辑',
        component: updateInfo,
        meta: {requireAuth: true},
        children: [
          {
            path: '/updateTInfoHome',
            name: '编辑教师信息',
            component: updateInfo,
            meta: {requireAuth: true}
          }
        ]
      },
      {
        path: '/courseManage',
        name: '课程设置',
        meta: {requireAuth: true},
        component: setCourse,
        children: [
          {
            path: '/myOfferCourse',
            name: '我开设的课程',
            component: myOfferCourse,
            meta: {requireAuth: true}
          },
          {
            path: '/offerCourseList',
            name: '开设课程',
            component: offerCourseList,
            meta: {requireAuth: true}
          },
        ]
      },
      {
        name: '教师成绩管理',
        path: '/teacherQueryGradeCourseManage',
        component: teacherGradeCourseManage,
        meta: {requireAuth: true},
        children: [
          {
            path: '/teacherGradeCourseList',
            name: '成绩管理',
            component: teacherGradeCourseList,
            meta: {requireAuth: true}
          },
          {
            path: '/teacherEditorGradeCourse',
            name: '编辑成绩',
            component: teacherEditorGradeCourse,
            meta: {requireAuth: true}
          }
        ]
      }
    ]
  },
  {//学生页面
    path: '/student',
    name: 'student',
    component: student,
    redirect: '/studentHome',
    children: [
      {
        path: '/student',
        name: 'hi! student',
        component: studentHome,
        children: [
          {
            path: '/studentHome',
            name: '学生主页',
            component: studentHome,
          },
        ],
      },
      {
        path: '/updateInfo',
        name: '学生编辑',
        component: updateInfo,
        meta: {requireAuth: true},
        children: [
          {
            path: '/updateSInfoHome',
            name: '编辑学生信息',
            component: updateInfo,
            meta: {requireAuth: true},
          }
        ]
      },
      {
        path: '/studentSelectCourseManage',
        name: '选课管理',
        component: studentSelectCourseManage,
        meta: {requireAuth: true},
        children: [
          {
            path: '/studentSelectCourse',
            name: '选课',
            component: selectCourse,
            meta: {requireAuth: true}
          },
          {
            path: '/querySelectedCourse',
            name: '查询课表',
            component: querySelectedCourse,
            meta: {requireAuth: true}
          },
          {
            path: '/courseTable',
            name: '课程表',
            component: courseTable,
            meta: {requireAuth: true}
          },
        ]
      },
      {
        path: '/courseGrade',
        name: '学生成绩管理',
        component: studentCourseGrade,
        meta: {requireAuth: true},
        children: [
          {
            path: '/queryCourseGrade',
            name: '成绩查询',
            component: queryCourseGrade,
            meta: {requireAuth: true}
          },
        ]
      }
    ]
  }
      
    ]
})
export default router

/*
  session 设置：
    1. token
    2. name
    3. type
    4. tid
    5. sid
    5. 系统信息 info
 */
    router.beforeEach((to, from, next) => {
      if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
        if (localStorage.getItem("token") !== '') { // 判断本地是否存在token
          next()
        } else {
          // 未登录,跳转到登陆页面
          next({
            path: '/login',
          })
        }
      } else {
        // 不需要登陆权限的页面，如果已经登陆，则跳转主页面
        if(localStorage.getItem("token") !== ''){
          console.log('检查拦截器配置，大概率出现漏网之鱼')
          next();
        }else{
          next();
        }
      }
    });

  